import mongoose from "mongoose"

const sentenceSchema = new mongoose.Schema({
  content: {
    type: String,
    unique: true,
    trim: true,
    required: [true, 'sentence must have a content!'],
    maxlength: [50, 'A content title must have less or equal then 50 characters'],
    minlength: [1, 'A content title must have more or equal then 1 characters'],
  },
  isDelete: {
    type: Boolean,
    select: false,
    default: false
  },
  createdAt: {
    type: Date,
    default: Date.now()
  }
})


sentenceSchema.post("save", function (doc, next) {
  // @ts-ignore 在返回对象时不携带该属性
  doc.isDelete = undefined
  next();
});
sentenceSchema.pre(/^find/, function (next) {
  this.find({ isDelete: { $eq: false } })
  next();
});
export default mongoose.model('Sentence', sentenceSchema)
